<?php
require_once('./class/Association.php');
require_once('./class/Statistique.php');
switch(@$_GET['action']){
    default:
        echo _ASSOCIATION_;
    break;

    case "addForm":
        echo Association::getAddForm();
        break;

    case "doAdd":
        $a = new Association();
        $a->setNom($_POST['nom']);
        $a->addOrModify();
        echo $a->getNom()." "._ADDED_;
        break;

    case "modifyForm":
        $a = Association::getAssociation($_GET['id']);
        echo $a->getModifyForm();
        break;

    case "doModify":
        $a = new Association();
        $a->setNom($_POST['nom']);
        $a->setId($_POST['id_association']);
        $a->addOrModify();
        echo _ASSOCIATION_.' '._MODIFIED_;
        break;

    case "list":
        $association_array = Association::getAllAssociation();
        $html = '<table class="tablesorter">
						<thead>
							<th>'._ID_ASSOCIATION_.'</th>
							<th>'._NOM_ASSOCIATION_.'</th>
							<th>'._FINANCE_.'</th>
							<th>'._LIST_ADHERENT_.'</th>
							<th>'._LIST_RESPONSABLE_.'</th>
							<th>'._EDIT_.'</th>
							<th>'._DELETE_.'</th>
						</thead><tbody>';
        $i = 0;
	$date = date('Y-m-d', time());
        foreach($association_array as $association){
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $finance = Statistique::getFinance($association->getId(), $date);
            $span = ($finance < 0) ? 'style="color: red"' : 'style="color: green"';
            $html .= '<tr '.$odd.'>
						<td>'.$association->getId().'</td>
						<td>'.$association->getNom().'</td>
						<td><span '.$span.'>'.$finance.'</span></td>
						<td><a href="?module=adhesion&action=list&id_association='.$association->getId().'">'._VOIR_.'</a></td>
						<td><a href="?module=responsable&action=list&id_association='.$association->getId().'">'._VOIR_.'</a></td>
						<td><a href="?module=association&action=modifyForm&id='.$association->getId().'">'._EDIT_.'</a></td>
						<td><a href="?module=association&action=delete&id='.$association->getId().'">'._DELETE_.'</a></td>
					</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;

    case "delete":
        $a = Association::getAssociation($_GET['id']);
        $a->delete();
        echo $a->getNom().' '._DELETED_;
        break;
}
?>
